home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / util / time / time_v12.lha / Time.c < prev   
C/C++ Source or Header  |  1994-12-31  |  2KB  |  93 lines

  1. ; /*
  2. sc time.c ignore=73
  3. slink from lib:c.o time.o to Time lib lib:sc.lib lib:amiga.lib sc sd nd
  4. quit
  5.  
  6.   Time v1.2 Copyright © 1994 by Stefano Reksten of 3AM - The Three Amigos!!!
  7.   This piece of code is FREEWARE. Do anything with it but don't gain money
  8.   for my work! And please spread exe + source!
  9.  
  10.   What does it do? Simply tells you how much time did a command take to
  11.   complete.
  12.  
  13.   rekststef@unisi.it
  14.  
  15.   Stefano Reksten c/o Naimi,
  16.   v.le Cavour 40,
  17.   53100 Siena
  18.   Italy
  19.  
  20. */
  21.  
  22. #include <exec/types.h>
  23. #include <exec/io.h>
  24. #include <devices/timer.h>
  25.  
  26. #include <clib/exec_protos.h>
  27. #include <clib/alib_protos.h>
  28. #include <clib/dos_protos.h>
  29. #include <clib/timer_protos.h>
  30. #include <dos.h>
  31. #include <stdlib.h>
  32. #include <stdio.h>
  33.  
  34. struct timeval start_time, end_time;
  35. struct Library *TimerBase;
  36. struct timerequest *tIO;
  37. struct MsgPort *mport;
  38. struct Message *msg;
  39. char *cmd_line;
  40. /*ULONG res_secs, res_micro;*/
  41. BPTR output;
  42.  
  43. #define RES_SECS    0
  44. #define RES_MICRO    1
  45.  
  46. ULONG    res[2];
  47.  
  48. char *template = "Command/A/F";
  49. char*ver = "$VER: Time v1.2 (31.12.94)";
  50.  
  51. void _main( char *line )
  52. {
  53. struct RDArgs *args;
  54.  
  55. if ( args = ReadArgs( template, (LONG *)&cmd_line, NULL ) )
  56.     {
  57.     if ( mport = CreateMsgPort() )
  58.         {
  59.         if ( tIO = (struct timerequest *)CreateExtIO(mport,sizeof(struct timerequest)) )
  60.             {
  61.             if ( !OpenDevice("timer.device",UNIT_VBLANK,(struct IORequest*)tIO,0L) )
  62.                 {
  63.                 TimerBase = (struct Library *)tIO->tr_node.io_Device;
  64.  
  65.                 output = Output();
  66.                 VFPrintf( output, "\2333mTime\2330m v1.2 by Stefano Reksten\n", NULL );
  67.                 GetSysTime( &start_time );
  68.  
  69.                 system( cmd_line );
  70.  
  71.                 GetSysTime( &end_time );
  72.  
  73.                 if ( end_time.tv_micro < start_time.tv_micro )
  74.                     {
  75.                     start_time.tv_secs--;
  76.                     res[RES_MICRO] = start_time.tv_micro - end_time.tv_micro;
  77.                     }
  78.                 else res[RES_MICRO] = end_time.tv_micro - start_time.tv_micro;
  79.  
  80.                 res[RES_SECS] = end_time.tv_secs - start_time.tv_secs;
  81.  
  82.                 VFPrintf( output, "Command took %ld secs, %ld micros to complete.\n", (LONG *)res );
  83.                 CloseDevice((struct IORequest *)tIO);
  84.                 }
  85.             DeleteExtIO((struct IORequest *)tIO);
  86.             }
  87.         DeleteMsgPort(mport);
  88.         }
  89.     FreeArgs( args );
  90.     }
  91. else PrintFault( IoErr(), NULL );
  92. }
  93.